package com.wjh.www.controller;

import com.wjh.www.annotation.spring.Autowired;
import com.wjh.www.annotation.spring.Component;
import com.wjh.www.annotation.springmvc.RequestBody;
import com.wjh.www.annotation.springmvc.RequestMapping;
import com.wjh.www.annotation.springmvc.RequestParam;
import com.wjh.www.entity.bo.TokenString;
import com.wjh.www.entity.bo.UserLoginBo;
import com.wjh.www.entity.dto.CommonResult;
import com.wjh.www.entity.po.User;
import com.wjh.www.entity.vo.UserInfoVo;
import com.wjh.www.service.impl.UserServiceImpl;

import javax.servlet.annotation.WebServlet;

/**
 * 用户相关接口
 *
 * @author wjh
 * @date 2021/9/11 10:52
 * @Package com.wjh.anyview.controller
 */
@WebServlet("/anyview/user/*")
@Component
public class UserController extends DispatcherController {
    @Autowired
    private UserServiceImpl userService;

    @RequestMapping("/login")
    CommonResult<String> login(@RequestBody UserLoginBo userLoginBo) {
        return userService.login(userLoginBo);
    }

    @RequestMapping("/register")
    CommonResult<?> register(@RequestBody User user) {
        return userService.register(user);
    }

    @RequestMapping("/addUser")
    CommonResult<?> addUser(@RequestBody User user) {
        return userService.saveUser(user);
    }

    @RequestMapping("/addStudent")
    CommonResult<?> addStudent(@RequestBody User user) {
        return userService.saveStudent(user);
    }

    @RequestMapping("/addAdmin")
    CommonResult<?> addAdmin(@RequestBody User user) {
        return userService.saveAdmin(user);
    }

    @RequestMapping("/selectUserByNum")
    CommonResult<UserInfoVo> selectUserByNum(@RequestParam("num") String num) {
        return userService.selectUserByNum(num);
    }

    @RequestMapping("/updateUserById")
    CommonResult<?> updateUserById(@RequestBody User user) {
        return userService.updateUserById(user);
    }

    @RequestMapping("/deleteUserById")
    CommonResult<?> deleteUserById(@RequestParam("userId") Long userId) {
        return userService.deleteUserById(userId);
    }

    @RequestMapping("/getUserByToken")
    CommonResult<User> getUserByToken(@RequestBody TokenString tokenString) {
        return userService.getUserByToken(tokenString.getTokenString());
    }

}
